<!--  -->
<template>
  <div class="proofread-item list-colum-width">
    <div>
      <p class="main-grammar" v-show="titleShow">
        {{ renderData.title }}
        <span v-show="allType !== '1'">
          <img
            class="play-btn"
            src="~assets/reverse/audio-play.png"
            alt=""
            @click.stop="audioPlay(renderData)"
          />
          <img
            class="translate-btn"
            src="~assets/reverse/translate-en.png"
            alt=""
            @click.stop="clickTranslate(renderData)"
          />
        </span>
      </p>
      <p class="main-grammar" v-show="translationShow">
        {{ renderData.translation }}
        <span v-show="allType === '1'">
          <img
            class="play-btn"
            src="~assets/reverse/audio-play.png"
            alt=""
            @click.stop="audioPlay(renderData)"
          />
          <img
            class="translate-btn"
            src="~assets/reverse/translate-en.png"
            alt=""
            @click.stop="clickTranslate(renderData)"
          />
        </span>
      </p>
    </div>
    <div class="check-grammar" v-if="isCheck">
      <div @click.stop="checkItem(renderData, '1')">
        <template v-if="checked === '1'">
          <img src="~/assets/reverse/success.png" alt="" />
        </template>
        <template v-else>
          <img src="~/assets/reverse/success-normal.png" alt="" />
        </template>
      </div>
      <div @click.stop="checkItem(renderData, '2')">
        <template v-if="checked === '2'">
          <img src="~/assets/reverse/error.png" alt="" />
        </template>
        <template v-else>
          <img src="~/assets/reverse/error-normal.png" alt="" />
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";

export default {
  name: "proofreadItem",
  components: {},
  data() {
    return {
      audio: {},
      translationShow: ["1", "3"].includes(this.allType) ? true : false,
      titleShow: ["2", "3"].includes(this.allType) ? true : false,
      checked: "",
    };
  },
  props: {
    renderData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    allType: {
      type: String,
    },
    isCheck: {
      type: Boolean,
    },
  },
  computed: {},
  watch: {
    allType: function(val) {
      console.log(val, "----");
      if (val === "1") {
        this.translationShow = true;
        this.titleShow = false;
      } else if (val === "2") {
        this.translationShow = false;
        this.titleShow = true;
      } else {
        this.translationShow = true;
        this.titleShow = true;
      }
    },
  },
  methods: {
    ...mapMutations(["setReverseAudio"]),
    clickTranslate(item) {
      console.log(item);
      if (this.allType === "1") {
        this.titleShow = !this.titleShow;
      } else {
        this.translationShow = !this.translationShow;
      }
    },
    audioPlay(item) {
      if (item.voice) {
        this.audio.src = item.voice;
        this.audio.play();
      }
    },
    checkItem(item, status) {
      console.log(item.id);
      this.checked = status;
      this.$emit("checkStatus", { id: item.id, status: status });
    },
  },
  created() {},
  mounted() {
    this.audio = document.getElementById("reverse-audio");
  },
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
};
</script>
<style lang="less" scoped>
/* @import url(); 引入公共css类 */
@import "@/style/var.less";
.proofread-item {
  display: flex;
  justify-content: space-between;
  padding: 30px 40px;
  background-color: #fff;
  border-radius: 10px;
  text-align: left;
  margin-bottom: 20px;
  transition: box-shadow 0.3s;
  &:hover {
    box-shadow: 0px 0px 10px rgba(39, 191, 163, 0.5);
  }

  // height: 200px;
  .main-grammar {
    font-size: 24px;
  }
  .play-btn,
  .translate-btn {
    width: 20px;
    height: 20px;
    margin-left: 20px;
  }
  .check-grammar {
    display: flex;
    align-items: center;
    img {
      width: 30px;
      height: 30px;
      margin-left: 20px;
    }
  }
}
</style>
